<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" class="input">
    <script>
        // 代理模式 -- 缓存代理
        const cache = {}
        async function getData(url) {
            if (cache[url]) {
                return cache[url]
            }
            const data = await fetch(url)
            cache[url] = data
            return data
        }
        document.querySelector('.input').addEventListener('keyup', function (e) {
            if (e.key === 'Enter') {
                const url = this.value
                getData(url).then(data => {
                    console.log(data)
                })
            }
        })
    </script>
</body>

</html>